using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Runtime.Serialization;
using System.Web.Security;

namespace TemplateWeb.DTO
{
	/// <summary>
	/// Data transfer object which is associated with NguoiChoiDauGia table in database
	/// </summary>
	public class NguoiChoiDauGiaDTO
	{
		public int ID { get; set; }
		public Guid IDNguoiDung { get; set; }
		public int IDPhienDauGia { get; set; }
		public DateTime ThoiDiemDauGia { get; set; }
		public long GiaDuaRa { get; set; }
        public NguoiDungDTO NguoiDung { get; set; }

		public static NguoiChoiDauGiaDTO Translate(DataRow row)
		{
			var dto = new NguoiChoiDauGiaDTO
			{
				ID = int.Parse(row["ID"].ToString()),
				IDNguoiDung = Guid.Parse(row["IDNguoiDung"].ToString()),
				IDPhienDauGia = int.Parse(row["IDPhienDauGia"].ToString()),
				ThoiDiemDauGia = DateTime.Parse(row["ThoiDiemDauGia"].ToString()),
				GiaDuaRa = long.Parse(row["GiaDuaRa"].ToString()),
			};

            var nd = new NguoiDungDTO
            {
                ID = dto.IDNguoiDung,
                HoTen = row["HoTen"].ToString(),
                DiaChi = row["DiaChi"].ToString(),
                SoDienThoai = row["SoDienThoai"].ToString(),
                SoTaiKhoan = row["SoTaiKhoan"].ToString()
            };
            dto.NguoiDung = nd;
            var mUser = Membership.GetUser(nd.ID);
            nd.aspnet_Users = new BaseInfo(mUser.UserName, mUser.Email, Roles.GetRolesForUser(mUser.UserName)[0], mUser.CreationDate);

			return dto;
		}
	}
}